<template>
	<div class="components-container">
        <div class="header-form">
            <el-tabs v-model="activeName" @tab-click="handleClick" class="tabsstyle">
                <el-tab-pane v-for="item in tabsarray" :label="item.CTPID" :name="item.CTPNAMEDESC" :key="item.CTPID"></el-tab-pane>
            </el-tabs>
        </div>
         <div>
            <ul class="toolList">
                <li v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>
        <dataTable ref="table" :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <codeManageMain ref="codeManageMain" @refreshData="getData"></codeManageMain>
	</div>


</template>
<style rel="stylesheet/scss" lang="scss" scoped>
    @import "src/styles/common.scss";
    .tabsstyle{
        width: 80vw;
        margin: 0 auto;
    }
</style>
<script>
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { manage } from "@/mixins/managePage.js";
import codeManageMain from "./codeManageMain"
const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
	export default {
        name: 'codingManage',
        mixins: [manage],
        data() {
            return {
                selectData:{
                    CodCtpIdEquals: null,
                },
                activeName: null, //标签页默认
                headList: [],
                dataList: [],
                tabsarray: [],
            }
        },
        methods: {
             //功能操作
            operate(order) {
                this.order = order;
                switch (this.order) {
                    case ADD:
                        this.$refs.codeManageMain.open(this.order,this.selectData.CodCtpIdEquals);
                    break;
                    case MODIFY:
                    case INFO:
                        this.$refs.codeManageMain.open(this.order,this.selectData.CodCtpIdEquals, this.currentRow);
                    break;
                    default:
                }
            },
            //收费项目查询
            getData() {
                let data = {}; 
                data.PageIndex= this.pageOrder.currentPage;
                data.PageSize= this.pageOrder.pageSize;
                data.OrderBy= this.pageOrder.orderType;
                data.OrderByType= this.pageOrder.orderSort;
                data.Data = JSON.parse(JSON.stringify(this.selectData))
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Code.Query,
                    res => {
                        this.dataList = res.data.content.OutData;
                        this.pageOrder.totalNum = res.data.content.RecordCount;
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    }
                );
            },
            //获取表头
            getChargeProjectColumn() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Column.GetBmxxColumns,
                    res => {
                        this.headList = res.data.content;
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    }
                );
            },
            //获取配置项的大类
            QueryCtp() {
                apiBase.DoService(    
                    {},
                    apiBase.getApiAdress().Code.QueryCtp,
                    res => {
                        this.tabsarray = res.data.content.OutData;
                        this.activeName = this.tabsarray[0].CTPID;//标签页默认
                        this.selectData.CodCtpIdEquals = this.tabsarray[0].CTPID;
                        this.getData();
                    },
                    res => {
                        this.$message.error('获取配置项失败！');
                    });
            },
            handleClick(tab){
                this.$refs.table.pageOrder.currentPage = 1;
                this.selectData = {CodCtpIdEquals:tab.label};
                this.getData();
            },
            //分页和排序
            pageChange(value) {
                this.pageOrder = value;
                this.getData();
            },
        },
        mounted() {
            this.getChargeProjectColumn();
            this.QueryCtp();
        },
        components: {
            dataTable,
            codeManageMain
        },
        created() {

        }
    }
</script>